I was reading a code saw the following line of the code and am just wondering to know how does this line of code work:
const roles = Object.values(foundUser.roles).filter(Boolean);
If this is the User Schema:
const userSchema = new Schema({
email: {
type: String,
required: true,
unique: true
},
username: {
type: String,
// required: true,
unique: true
},
password: {
type: String,
required: true
},
roles: {
User: {
type: Number,
default: 2001
},
Editor: Number,
Admin: Number
},
refreshToken: [String]
});
I can't understand what does the filter(Boolean) function do? What does Boolean as input mean? What goes to the filter() and what comes out from it?
EDIT: For example if we have a User object that has the default value of roles: {User: {type: Number, default: 2001} , Editor: undefined , Admin: undefined}
what would be the value of
const roles? [2001] or [User]?